Home   Cover Cover Cover Cover
 

Statische Variablen und Methoden

../../solutions/2/Static.cs
using System;

class C {
  static int objects = 0;
  public int x, y;
  
  public C() {
    x = 0; y = 0;
    objects++;
  }
  
  public static int ObjectCounter {
    get { return objects; }
  }
  
  public static void ResetObjectCounter() {
    objects = 0;
  }
}

class Test {
  
  public static void Main() {
    C a = new C();
    C b = new C();
    C c = new C();
    Console.WriteLine(C.ObjectCounter + " objects of C were created");
    C.ResetObjectCounter();
    a = new C();
    c = new C();
    Console.WriteLine(C.ObjectCounter + " objects of C were created");
  }
}